<?php
/**
 * Created by PhpStorm.
 * User: 小灰灰
 * Date: 2022-04-21
 * Time: 14:01:36
 * Info:
 */

namespace app\admin\controller;

use support\Request;
use think\Validate;

class CommonController extends \app\BaseController
{

    protected $validate;

    public $adminId = 0;

    /**
     * 数据限制
     * 例如当$dataLimit='admin_id'时将只返回当前管理员的数据
     * @var string
     */
    protected $dataLimit = null;

    public function __construct()
    {
        $this->validate = new Validate();
    }

    // 生成用户token
    protected function createToken($admin_id)
    {
        $token = md5('admin_id_'.$admin_id.'_'.time());

        return $token;
    }

    // 更新token缓存
    protected function updateTokenExpire($token, $admin_id)
    {
        if ( ! $token || ! $admin_id) {
            return false;
        }

        session()->set($token, $admin_id);

        return true;
    }

}
